function showContent(href) {
    window.frames['viewContent'].contentWindow.location = href;
}
let isFlushHash = false;

function showUrl() {
    let subLoc = window.frames["viewContent"].contentWindow.location;
    let pe = subLoc.href;
    let pc = `${window.location.host}${window.location.pathname}#${pe.substring(pe.indexOf(subLoc.pathname))}`;

    isFlushHash = true;
    window.location.hash = pe.substring(pe.indexOf(subLoc.pathname));

    showFull(true, `<h2>页面链接</h2><input style="width:100%;border:0;" type="text" editable="false" value="${pc}" /><h2>手机端</h2><input style="width:100%;border:0;" type="text" editable="false" value="${pe}" />`);
}

function showFull(show, data) {
    if (show) {
        $("#output").html(data);
        $("#output").show();
        $("#outputBackground").show();
    } else {
        $("#output").hide();
        $("#outputBackground").hide();
    }
}

//子容器长度监听
(() => {
    // setInterval(() => {
    //     let s = window.scrollY;
    //     let tar = $("#viewContent");
    //     tar.height(0);
    //     let hei = tar.contents().height() + 10;
    //     tar.height(hei);
    //     window.scroll(window.scrollX, s);
    // }, 50);
})();

//页面定向
window.onhashchange = () => {
    if (isFlushHash) return isFlushHash = false;
    window.frames["viewContent"].src = (window.location.hash || "#/public/cloud-cat.html").substring(1);
}
$(window.onhashchange);
(() => {
    let isBottom = false;
    let onScrollBottom = () => {
        let func = (window.frames["viewContent"].contentWindow || {}).onScrollBottom;
        if (typeof func === 'function') func();
    }
    //滚动监听
    $(window).scroll(function() {
        $("#nav").css('top', window.scrollY);
        var scrollTop = $(this).scrollTop();
        var scrollHeight = $(document).height();
        var windowHeight = $(this).height();
        if (scrollTop + windowHeight + 50 >= scrollHeight) {
            if (isBottom) return;
            else isBottom = true;
            onScrollBottom();
        } else isBottom = false;
    });
})();